home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
LANG
/
GNUST
/
Demos
/
RandomInte
< prev
Wrap
Text File
|
1991-09-13
|
536b
|
32 lines
"By Andy Valencia (uunet!sequent!vandys)"
"A source of random integers"
Integer subclass: #RandomInteger
instanceVariableNames: ''
classVariableNames: 'Source'
poolDictionaries: ''
category: nil.
!
RandomInteger comment:
'My instances are random integers'
!
!RandomInteger class methodsFor: 'instance creation'!
new
^ self error: 'Must use between:and:'
!
between: low and: high
| i range |
(Source = nil) ifTrue: [ Source _ Random new ].
range _ high - low.
i _ (((Source next) * (range + 1)) + low) rounded.
^ i
!!